package chttl;

import java.io.IOException;
import java.io.PrintStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.*;
import netscape.ldap.*;
import netscape.ldap.util.DN;

// Referenced classes of package chttl:
//            BASE64Encoder, CharacterEncoder

public class OpenLDAPAPI {

	public OpenLDAPAPI() {
		ld = new LDAPConnection();
		base = null;
		resultCode = -1;
		resultCodeString = null;
		dirSchema = new LDAPSchema();
	}

	public OpenLDAPAPI(LDAPSocketFactory sfactory) {
		ld = new LDAPConnection(sfactory);
		base = null;
		resultCode = -1;
		resultCodeString = null;
		dirSchema = new LDAPSchema();
	}

	public void connect(String s, int i) {
		resultCode = 0;
		resultCodeString = new String("The connect is success!");
		try {
			ld.connect(s, i);
		} catch (LDAPException ldapexception) {
			resultCodeString = new String(ldapexception.toString());
			resultCode = ldapexception.getLDAPResultCode();
			return;
		}
	}

	public void connectAndAuthenticate(int version, String host, int port, String dn, String passwd) {
		resultCode = 0;
		resultCodeString = new String("The connect and authentication is success!");
		try {
			ld.connect(version, host, port, dn, passwd);
		} catch (LDAPException ldapexception) {
			resultCodeString = new String(ldapexception.toString());
			resultCode = ldapexception.getLDAPResultCode();
			return;
		}
	}

	public void authenticate(String s, String s1) {
		resultCode = 0;
		resultCodeString = new String("The authenticate is success!");
		try {
			ld.authenticate(s, s1);
		} catch (LDAPException ldapexception) {
			resultCodeString = new String(ldapexception.toString());
			resultCode = ldapexception.getLDAPResultCode();
			return;
		}
	}

	public void setSizeOption(Integer integer) {
		resultCode = 0;
		resultCodeString = new String("setSizeOption is success!");
		try {
			ld.setOption(LDAPv2.SIZELIMIT, integer);
		} catch (LDAPException ldapexception) {
			resultCodeString = new String(ldapexception.toString());
			resultCode = ldapexception.getLDAPResultCode();
			return;
		}
	}

	public void close() {
		resultCode = 0;
		resultCodeString = null;
		if (ld != null && ld.isConnected())
			try {
				ld.disconnect();
			} catch (LDAPException ldapexception) {
				resultCodeString = new String(ldapexception.toString());
				resultCode = ldapexception.getLDAPResultCode();
			}
	}

	public void setDefaultBase(String s) {
		base = new String(s);
	}

	public int getResultCode() {
		return resultCode;
	}

	public String getResultCodeString() {
		return resultCodeString;
	}

	public String getSingleStringValueByDN(String s, String s1) {
		resultCode = -1;
		resultCodeString = new String("The attribute is not found!");
		LDAPEntry ldapentry = null;
		if (s1 == null || !DN.isDN(s1))
			return null;
		try {
			String s2 = "(" + s + "=*)";
			String as[] = new String[1];
			as[0] = new String(s);
			LDAPSearchResults ldapsearchresults = ld.search(s1, LDAPv2.SCOPE_BASE, s2, as, false);
			if (ldapsearchresults == null)
				return null;
			while (ldapsearchresults.hasMoreElements()) {
				try {
					ldapentry = ldapsearchresults.next();
				} catch (LDAPReferralException ldapreferralexception) {
					System.out.println("Search references: ");
					LDAPUrl aldapurl[] = ldapreferralexception.getURLs();
					for (int i = 0; i < aldapurl.length;) {
						System.out.println("\t" + aldapurl[i].getUrl());
						return null;
					}

				} catch (LDAPException ldapexception1) {
					resultCodeString = new String(ldapexception1.toString());
					resultCode = ldapexception1.getLDAPResultCode();
					return null;
				}
				LDAPAttribute ldapattribute = ldapentry.getAttribute(s);
				Enumeration enumeration = ldapattribute.getStringValues();
				if (enumeration != null && enumeration.hasMoreElements()) {
					String s3 = (String) enumeration.nextElement();
					if (s3 != null) {
						resultCode = 0;
						resultCodeString = new String("Search is successful!");
						return s3;
					}
				}
			}
		} catch (LDAPException ldapexception) {
			resultCodeString = new String(ldapexception.toString());
			resultCode = ldapexception.getLDAPResultCode();
			return null;
		}
		return null;
	}

	public byte[] getSingleByteValueByDN(String s, String s1) {
		resultCode = -1;
		resultCodeString = new String("The attribute is not found!");
		Object obj = null;
		if (s1 == null || !DN.isDN(s1))
			return null;
		try {
			String s2 = "(" + s + "=*)";
			String as[] = new String[1];
			as[0] = new String(s);
			LDAPSearchResults ldapsearchresults = ld.search(s1, LDAPv2.SCOPE_BASE, s2, as, false);
			if (ldapsearchresults == null)
				return null;
			while (ldapsearchresults.hasMoreElements()) {
				LDAPEntry ldapentry;
				try {
					ldapentry = ldapsearchresults.next();
				} catch (LDAPReferralException ldapreferralexception) {
					System.out.println("Search references: ");
					LDAPUrl aldapurl[] = ldapreferralexception.getURLs();
					for (int i = 0; i < aldapurl.length; i++)
						System.out.println("\t" + aldapurl[i].getUrl());

					continue;
				} catch (LDAPException ldapexception1) {
					resultCodeString = new String(ldapexception1.toString());
					resultCode = ldapexception1.getLDAPResultCode();
					continue;
				}
				LDAPAttribute ldapattribute = ldapentry.getAttribute(s);
				Enumeration enumeration = ldapattribute.getByteValues();
				if (enumeration != null && enumeration.hasMoreElements()) {
					resultCode = 0;
					resultCodeString = new String("Search is successful!");
					return (byte[]) enumeration.nextElement();
				}
			}
		} catch (LDAPException ldapexception) {
			resultCodeString = new String(ldapexception.toString());
			resultCode = ldapexception.getLDAPResultCode();
		}
		return null;
	}

	public String getSingleStringValueByKey(String s, String s1, String s2, String s3) {
		resultCode = -1;
		resultCodeString = new String("The attribute is not found!");
		Object obj = null;
		try {
			String s4 = "(&(" + s + "=" + s1 + ")" + "(" + s2 + "=*)" + ")";
			String as[] = new String[1];
			as[0] = new String(s2);
			LDAPSearchResults ldapsearchresults;
			if (s3 != null)
				ldapsearchresults = ld.search(s3, LDAPv2.SCOPE_SUB, s4, as, false);
			else
				ldapsearchresults = ld.search(base, LDAPv2.SCOPE_SUB, s4, as, false);
			if (ldapsearchresults == null)
				return null;
			while (ldapsearchresults.hasMoreElements()) {
				LDAPEntry ldapentry;
				try {
					ldapentry = ldapsearchresults.next();
				} catch (LDAPReferralException ldapreferralexception) {
					System.out.println("Search references: ");
					LDAPUrl aldapurl[] = ldapreferralexception.getURLs();
					for (int i = 0; i < aldapurl.length; i++)
						System.out.println("\t" + aldapurl[i].getUrl());

					continue;
				} catch (LDAPException ldapexception1) {
					resultCodeString = new String(ldapexception1.toString());
					resultCode = ldapexception1.getLDAPResultCode();
					continue;
				}
				LDAPAttribute ldapattribute = ldapentry.getAttribute(s2);
				Enumeration enumeration = ldapattribute.getStringValues();
				if (enumeration != null && enumeration.hasMoreElements()) {
					resultCode = 0;
					resultCodeString = new String("Search is successful!");
					return (String) enumeration.nextElement();
				}
			}
		} catch (LDAPException ldapexception) {
			resultCodeString = new String(ldapexception.toString());
			resultCode = ldapexception.getLDAPResultCode();
		}
		return null;
	}

	public byte[] getSingleByteValueByKey(String s, String s1, String s2, String s3) {
		resultCode = -1;
		resultCodeString = new String("The attribute is not found!");
		Object obj = null;
		try {
			String s4 = "(&(" + s + "=" + s1 + ")" + "(" + s2 + "=*)" + ")";
			String as[] = new String[1];
			as[0] = new String(s2);
			LDAPSearchResults ldapsearchresults;
			if (s3 != null)
				ldapsearchresults = ld.search(s3, LDAPv2.SCOPE_SUB, s4, as, false);
			else
				ldapsearchresults = ld.search(base, LDAPv2.SCOPE_SUB, s4, as, false);
			if (ldapsearchresults == null)
				return null;
			while (ldapsearchresults.hasMoreElements()) {
				LDAPEntry ldapentry;
				try {
					ldapentry = ldapsearchresults.next();
				} catch (LDAPReferralException ldapreferralexception) {
					System.out.println("Search references: ");
					LDAPUrl aldapurl[] = ldapreferralexception.getURLs();
					for (int i = 0; i < aldapurl.length; i++)
						System.out.println("\t" + aldapurl[i].getUrl());

					continue;
				} catch (LDAPException ldapexception1) {
					resultCodeString = new String(ldapexception1.toString());
					resultCode = ldapexception1.getLDAPResultCode();
					continue;
				}
				LDAPAttribute ldapattribute = ldapentry.getAttribute(s2);
				Enumeration enumeration = ldapattribute.getByteValues();
				if (enumeration != null && enumeration.hasMoreElements()) {
					resultCode = 0;
					resultCodeString = new String("Search is successful!");
					return (byte[]) enumeration.nextElement();
				}
			}
		} catch (LDAPException ldapexception) {
			resultCodeString = new String(ldapexception.toString());
			resultCode = ldapexception.getLDAPResultCode();
		}
		return null;
	}

	public String[] getMultiStringValuesByDN(String s, String s1) {
		resultCode = -1;
		resultCodeString = new String("The attribute is not found!");
		Object obj = null;
		boolean flag = false;
		if (s1 == null || !DN.isDN(s1))
			return null;
		try {
			String s2 = "(" + s + "=*)";
			String as[] = new String[1];
			as[0] = new String(s);
			LDAPSearchResults ldapsearchresults = ld.search(s1, LDAPv2.SCOPE_BASE, s2, as, false);
			if (ldapsearchresults == null)
				return null;
			while (ldapsearchresults.hasMoreElements()) {
				LDAPEntry ldapentry;
				try {
					ldapentry = ldapsearchresults.next();
				} catch (LDAPReferralException ldapreferralexception) {
					System.out.println("Search references: ");
					LDAPUrl aldapurl[] = ldapreferralexception.getURLs();
					for (int j = 0; j < aldapurl.length; j++)
						System.out.println("\t" + aldapurl[j].getUrl());

					continue;
				} catch (LDAPException ldapexception1) {
					resultCodeString = new String(ldapexception1.toString());
					resultCode = ldapexception1.getLDAPResultCode();
					continue;
				}
				LDAPAttribute ldapattribute = ldapentry.getAttribute(s);
				int i = ldapattribute.size();
				if (i != 0 && ldapattribute.getStringValueArray() != null) {
					resultCode = 0;
					resultCodeString = new String("Search is successful!");
					return ldapattribute.getStringValueArray();
				} else {
					return null;
				}
			}
		} catch (LDAPException ldapexception) {
			resultCodeString = new String(ldapexception.toString());
			resultCode = ldapexception.getLDAPResultCode();
		}
		return null;
	}

	public byte[][] getMultiByteValuesByDN(String s, String s1) {
		resultCode = -1;
		resultCodeString = new String("The attribute is not found!");
		Object obj = null;
		boolean flag = false;
		if (s1 == null || !DN.isDN(s1))
			return null;
		try {
			String s2 = "(" + s + "=*)";
			String as[] = new String[1];
			as[0] = new String(s);
			LDAPSearchResults ldapsearchresults = ld.search(s1, LDAPv2.SCOPE_BASE, s2, as, false);
			if (ldapsearchresults == null)
				return null;
			while (ldapsearchresults.hasMoreElements()) {
				LDAPEntry ldapentry;
				try {
					ldapentry = ldapsearchresults.next();
				} catch (LDAPReferralException ldapreferralexception) {
					System.out.println("Search references: ");
					LDAPUrl aldapurl[] = ldapreferralexception.getURLs();
					for (int j = 0; j < aldapurl.length; j++)
						System.out.println("\t" + aldapurl[j].getUrl());

					continue;
				} catch (LDAPException ldapexception1) {
					resultCodeString = new String(ldapexception1.toString());
					resultCode = ldapexception1.getLDAPResultCode();
					continue;
				}
				LDAPAttribute ldapattribute = ldapentry.getAttribute(s);
				int i = ldapattribute.size();
				if (i != 0 && ldapattribute.getByteValueArray() != null) {
					resultCode = 0;
					resultCodeString = new String("Search is successful!");
					return ldapattribute.getByteValueArray();
				} else {
					return null;
				}
			}
		} catch (LDAPException ldapexception) {
			resultCodeString = new String(ldapexception.toString());
			resultCode = ldapexception.getLDAPResultCode();
		}
		return null;
	}

	public String[] getMultiStringValuesByKey(String s, String s1, String s2, String s3) {
		resultCode = -1;
		resultCodeString = new String("The attribute is not found!");
		Object obj = null;
		try {
			String s4 = "(&(" + s + "=" + s1 + ")" + "(" + s2 + "=*)" + ")";
			String as[] = new String[1];
			as[0] = new String(s2);
			LDAPSearchResults ldapsearchresults;
			if (s3 != null)
				ldapsearchresults = ld.search(s3, LDAPv2.SCOPE_SUB, s4, as, false);
			else
				ldapsearchresults = ld.search(base, LDAPv2.SCOPE_SUB, s4, as, false);
			if (ldapsearchresults == null)
				return null;
			while (ldapsearchresults.hasMoreElements()) {
				LDAPEntry ldapentry;
				try {
					ldapentry = ldapsearchresults.next();
				} catch (LDAPReferralException ldapreferralexception) {
					System.out.println("Search references: ");
					LDAPUrl aldapurl[] = ldapreferralexception.getURLs();
					for (int j = 0; j < aldapurl.length; j++)
						System.out.println("\t" + aldapurl[j].getUrl());

					continue;
				} catch (LDAPException ldapexception1) {
					resultCodeString = new String(ldapexception1.toString());
					resultCode = ldapexception1.getLDAPResultCode();
					continue;
				}
				LDAPAttribute ldapattribute = ldapentry.getAttribute(s2);
				int i = ldapattribute.size();
				if (i != 0 && ldapattribute.getStringValueArray() != null) {
					resultCode = 0;
					resultCodeString = new String("Search is successful!");
					return ldapattribute.getStringValueArray();
				}
			}
		} catch (LDAPException ldapexception) {
			resultCodeString = new String(ldapexception.toString());
			resultCode = ldapexception.getLDAPResultCode();
		}
		return null;
	}

	public byte[][] getMultiByteValuesByKey(String s, String s1, String s2, String s3) {
		resultCode = -1;
		resultCodeString = new String("The attribute is not found!");
		Object obj = null;
		try {
			String s4 = "(&(" + s + "=" + s1 + ")" + "(" + s2 + "=*)" + ")";
			String as[] = new String[1];
			as[0] = new String(s2);
			LDAPSearchResults ldapsearchresults;
			if (s3 != null)
				ldapsearchresults = ld.search(s3, LDAPv2.SCOPE_SUB, s4, as, false);
			else
				ldapsearchresults = ld.search(base, LDAPv2.SCOPE_SUB, s4, as, false);
			if (ldapsearchresults == null)
				return null;
			while (ldapsearchresults.hasMoreElements()) {
				LDAPEntry ldapentry;
				try {
					ldapentry = ldapsearchresults.next();
				} catch (LDAPReferralException ldapreferralexception) {
					System.out.println("Search references: ");
					LDAPUrl aldapurl[] = ldapreferralexception.getURLs();
					for (int j = 0; j < aldapurl.length; j++)
						System.out.println("\t" + aldapurl[j].getUrl());

					continue;
				} catch (LDAPException ldapexception1) {
					resultCodeString = new String(ldapexception1.toString());
					resultCode = ldapexception1.getLDAPResultCode();
					continue;
				}
				LDAPAttribute ldapattribute = ldapentry.getAttribute(s2);
				int i = ldapattribute.size();
				if (i != 0 && ldapattribute.getByteValueArray() != null) {
					resultCode = 0;
					resultCodeString = new String("Search is successful!");
					return ldapattribute.getByteValueArray();
				}
			}
		} catch (LDAPException ldapexception) {
			resultCodeString = new String(ldapexception.toString());
			resultCode = ldapexception.getLDAPResultCode();
		}
		return null;
	}

	public String[] getDNsByKey(String s, String s1) {
		resultCode = -1;
		resultCodeString = new String("The attribute is not found!");
		Object obj = null;
		Vector vector = new Vector();
		String as[] = null;
		int i = 0;
		try {
			String s2 = "(" + s + "=" + s1 + ")";
			String as1[] = new String[1];
			as1[0] = new String("LDAPv3.NO_ATTRS");
			LDAPSearchResults ldapsearchresults = ld.search(base, LDAPv2.SCOPE_SUB, s2, as1, true);
			if (ldapsearchresults == null)
				return null;
			if (!ldapsearchresults.hasMoreElements())
				return null;
			while (ldapsearchresults.hasMoreElements()) {
				LDAPEntry ldapentry;
				try {
					ldapentry = ldapsearchresults.next();
				} catch (LDAPReferralException ldapreferralexception) {
					continue;
				} catch (LDAPException ldapexception1) {
					resultCodeString = new String(ldapexception1.toString());
					resultCode = ldapexception1.getLDAPResultCode();
					return null;
				}
				vector.add(ldapentry.getDN());
			}
		} catch (LDAPException ldapexception) {
			resultCodeString = new String(ldapexception.toString());
			resultCode = ldapexception.getLDAPResultCode();
			return null;
		}
		if (vector.size() == 0)
			return null;
		i = vector.size();
		as = new String[i];
		for (int j = 0; j < i; j++)
			as[j] = (String) vector.get(j);

		resultCode = 0;
		resultCodeString = new String("Search is successful!");
		return as;
	}

	public String[] getDNsBySelfConditions(String s, String s1, int i) {
		resultCode = -1;
		resultCodeString = new String("The entries are not found!");
		Object obj = null;
		Vector vector = new Vector();
		String as[] = null;
		int j = 0;
		try {
			String as1[] = new String[1];
			as1[0] = new String("LDAPv3.NO_ATTRS");
			LDAPSearchResults ldapsearchresults = ld.search(s, i, s1, as1, true);
			if (ldapsearchresults == null)
				return null;
			while (ldapsearchresults.hasMoreElements()) {
				LDAPEntry ldapentry;
				try {
					ldapentry = ldapsearchresults.next();
				} catch (LDAPReferralException ldapreferralexception) {
					continue;
				} catch (LDAPException ldapexception1) {
					resultCodeString = new String(ldapexception1.toString());
					resultCode = ldapexception1.getLDAPResultCode();
					return null;
				}
				vector.add(ldapentry.getDN());
			}
		} catch (LDAPException ldapexception) {
			resultCodeString = new String(ldapexception.toString());
			resultCode = ldapexception.getLDAPResultCode();
			return null;
		}
		if (vector.size() == 0)
			return null;
		j = vector.size();
		as = new String[j];
		for (int k = 0; k < j; k++)
			as[k] = (String) vector.get(k);

		resultCode = 0;
		resultCodeString = new String("Search is successful!");
		return as;
	}

	public String[] getDNsByMultiKeys(String as[], String s, String s1) {
		resultCode = -1;
		resultCodeString = new String("The attribute is not found!");
		Object obj = null;
		Vector vector = new Vector();
		String as1[] = null;
		int i = 0;
		int j = as.length;
		try {
			String s2 = "(" + s;
			for (int k = 0; k < j; k++) {
				s2 = s2.concat("(");
				s2 = s2.concat(as[k]);
				s2 = s2.concat(")");
			}

			s2 = s2.concat(")");
			String as2[] = new String[1];
			as2[0] = new String("LDAPv3.NO_ATTRS");
			LDAPSearchResults ldapsearchresults;
			if (s1 != null)
				ldapsearchresults = ld.search(s1, LDAPv2.SCOPE_SUB, s2, as2, false);
			else
				ldapsearchresults = ld.search(base, LDAPv2.SCOPE_SUB, s2, as2, false);
			if (ldapsearchresults == null)
				return null;
			while (ldapsearchresults.hasMoreElements()) {
				LDAPEntry ldapentry;
				try {
					ldapentry = ldapsearchresults.next();
				} catch (LDAPReferralException ldapreferralexception) {
					continue;
				} catch (LDAPException ldapexception1) {
					resultCodeString = new String(ldapexception1.toString());
					resultCode = ldapexception1.getLDAPResultCode();
					return null;
				}
				vector.add(ldapentry.getDN());
			}
		} catch (LDAPException ldapexception) {
			resultCodeString = new String(ldapexception.toString());
			resultCode = ldapexception.getLDAPResultCode();
			return null;
		}
		if (vector.size() == 0)
			return null;
		i = vector.size();
		as1 = new String[i];
		for (int l = 0; l < i; l++)
			as1[l] = (String) vector.get(l);

		resultCode = 0;
		resultCodeString = new String("Search is successful!");
		return as1;
	}

	public String[] getDNsBySelfConditions(String s, String as[], String as1[], String s1, int i) {
		resultCode = -1;
		resultCodeString = new String("The Search is failed!");
		Object obj = null;
		Object obj1 = null;
		String as2[] = null;
		Object obj2 = null;
		boolean flag = false;
		if (s == null || as == null || as1 == null || s1 == null)
			return null;
		String s2 = null;
		if (s1.equals("|"))
			s2 = new String("(|");
		else
			s2 = new String("(&");
		for (int j = 0; j < as.length; j++)
			s2 = new String(s2 + "(" + as[j] + "=*)");

		s2 = new String(s2 + ")");
		try {
			LDAPSearchResults ldapsearchresults = ld.search(s, i, s2, as, false);
			if (ldapsearchresults == null)
				return null;
			if (!ldapsearchresults.hasMoreElements())
				return null;
			while (ldapsearchresults.hasMoreElements()) {
				LDAPEntry ldapentry;
				try {
					ldapentry = ldapsearchresults.next();
				} catch (LDAPReferralException ldapreferralexception) {
					continue;
				} catch (LDAPException ldapexception1) {
					resultCodeString = new String(ldapexception1.toString());
					resultCode = ldapexception1.getLDAPResultCode();
					return null;
				}
				boolean flag1 = false;
				for (int k = 0; k < as.length; k++) {
					LDAPAttribute ldapattribute = ldapentry.getAttribute(as[k]);
					if (ldapattribute == null)
						break;
					byte abyte0[][] = ldapattribute.getByteValueArray();
					if (abyte0 == null)
						break;
					boolean flag2 = false;
					for (int i1 = 0; i1 < abyte0.length; i1++) {
						String s3;
						try {
							s3 = new String(abyte0[i1], "Big5");
						} catch (Exception exception) {
							resultCodeString = new String(exception.toString());
							return null;
						}
						String s4 = new String(as1[k]);
						if (s4.indexOf("*") >= 0) {
							if (s4.indexOf("*") > 0) {
								s4 = new String(s4.substring(0, s4.indexOf("*")));
							} else {
								flag2 = true;
								break;
							}
							if (!s3.startsWith(s4))
								continue;
							flag2 = true;
							break;
						}
						if (!s3.equals(s4))
							continue;
						flag2 = true;
						break;
					}

					if (flag2 && s1.equals("|")) {
						flag1 = true;
						break;
					}
					if (s1.equals("&") && !flag2)
						break;
					if (!s1.equals("&") || !flag2 || k != as.length - 1)
						continue;
					flag1 = true;
					break;
				}

				if (flag1)
					if (as2 == null) {
						as2 = new String[1];
						as2[0] = new String(ldapentry.getDN());
					} else {
						String as3[] = new String[as2.length + 1];
						for (int l = 0; l < as2.length; l++)
							as3[l] = new String(as2[l]);

						as3[as2.length] = new String(ldapentry.getDN());
						as2 = as3;
					}
			}
		} catch (LDAPException ldapexception) {
			resultCodeString = new String(ldapexception.toString());
			resultCode = ldapexception.getLDAPResultCode();
			return null;
		}
		if (as2 != null) {
			resultCode = 0;
			resultCodeString = new String("The Search is successful");
			return as2;
		} else {
			return null;
		}
	}

	public String[] getUnusedAttributesByDN(String s) {
		resultCode = -1;
		resultCodeString = new String("The entry is not found!");
		if (s == null || !DN.isDN(s))
			return null;
		String as[] = getMultiStringValuesByDN("objectclass", s);
		if (resultCode != 0)
			return null;
		String as1[] = null;
		String as2[] = getUsedAttributesByDN(s);
		for (int i = 0; i < as.length; i++) {
			String as3[] = getRequiredAttributes(as[i]);
			String as4[] = getOptionalAttributes(as[i]);
			if (as3 != null) {
				for (int j = 0; j < as3.length; j++) {
					boolean flag = false;
					for (int l = 0; l < as2.length; l++) {
						if (!as2[l].equalsIgnoreCase(as3[j]))
							continue;
						flag = true;
						break;
					}

					if (!flag)
						if (as1 != null) {
							String as5[] = new String[as1.length + 1];
							System.arraycopy(as1, 0, as5, 0, as1.length);
							as5[as1.length] = new String(as3[j]);
							as1 = as5;
							as5 = new String[as2.length + 1];
							System.arraycopy(as2, 0, as5, 0, as2.length);
							as5[as2.length] = new String(as3[j]);
							as2 = as5;
						} else {
							as1 = new String[1];
							as1[0] = new String(as3[j]);
							String as6[] = new String[as2.length + 1];
							System.arraycopy(as2, 0, as6, 0, as2.length);
							as6[as2.length] = new String(as3[j]);
							as2 = as6;
						}
				}

			}
			if (as4 != null) {
				for (int k = 0; k < as4.length; k++) {
					boolean flag1 = false;
					for (int i1 = 0; i1 < as2.length; i1++) {
						if (!as2[i1].equalsIgnoreCase(as4[k]))
							continue;
						flag1 = true;
						break;
					}

					if (!flag1)
						if (as1 != null) {
							String as7[] = new String[as1.length + 1];
							System.arraycopy(as1, 0, as7, 0, as1.length);
							as7[as1.length] = new String(as4[k]);
							as1 = as7;
							as7 = new String[as2.length + 1];
							System.arraycopy(as2, 0, as7, 0, as2.length);
							as7[as2.length] = new String(as4[k]);
							as2 = as7;
						} else {
							as1 = new String[1];
							as1[0] = new String(as4[k]);
							String as8[] = new String[as2.length + 1];
							System.arraycopy(as2, 0, as8, 0, as2.length);
							as8[as2.length] = new String(as4[k]);
							as2 = as8;
						}
				}

			}
		}

		if (as1 != null) {
			resultCode = 0;
			resultCodeString = new String("The number of unused attrs is " + as1.length);
			return as1;
		} else {
			resultCode = -1;
			resultCodeString = new String("The entry is not found!");
			return null;
		}
	}

	public String[][] getUnusedAttributesAndTypeByDN(String s) {
		resultCode = -1;
		resultCodeString = new String("The entry is not found!");
		if (s == null || !DN.isDN(s))
			return null;
		String as[][] = null;
		Vector vector = new Vector();
		int i = 0;
		try {
			String s1 = "(objectclass=*)";
			LDAPSearchResults ldapsearchresults = ld.search(s, LDAPv2.SCOPE_BASE, s1, null, false);
			if (ldapsearchresults == null)
				return null;
			Object obj = null;
			while (ldapsearchresults.hasMoreElements()) {
				LDAPEntry ldapentry;
				try {
					ldapentry = ldapsearchresults.next();
				} catch (LDAPReferralException ldapreferralexception) {
					System.out.println("Search references: ");
					LDAPUrl aldapurl[] = ldapreferralexception.getURLs();
					for (int l = 0; l < aldapurl.length; l++) {
						System.out.println("\t" + aldapurl[l].getUrl());
						resultCodeString = new String(ldapreferralexception.toString());
						resultCode = ldapreferralexception.getLDAPResultCode();
					}

					continue;
				} catch (LDAPException ldapexception1) {
					resultCodeString = new String(ldapexception1.toString());
					resultCode = ldapexception1.getLDAPResultCode();
					return null;
				}
				LDAPAttributeSet ldapattributeset = ldapentry.getAttributeSet();
				LDAPAttribute ldapattribute;
				for (Enumeration enumeration = ldapattributeset.getAttributes(); enumeration.hasMoreElements(); vector.add(ldapattribute.getName()
						.toLowerCase())) {
					i++;
					ldapattribute = (LDAPAttribute) enumeration.nextElement();
				}

			}
		} catch (LDAPException ldapexception) {
			resultCodeString = new String(ldapexception.toString());
			resultCode = ldapexception.getLDAPResultCode();
			return null;
		}
		String as1[][] = getOptionalAttributesAndTypeByDN(s);
		if (resultCode != 0)
			return null;
		Vector vector1 = new Vector();
		for (int j = 0; j < as1.length; j++)
			if (!vector.contains(as1[j][0].toLowerCase()))
				vector1.add(as1[j]);

		as = new String[vector1.size()][3];
		for (int k = 0; k < vector1.size(); k++) {
			String as2[] = (String[]) vector1.get(k);
			as[k][0] = as2[0];
			as[k][1] = as2[1];
			as[k][2] = as2[2];
		}

		resultCode = 0;
		resultCodeString = new String("The number of unused attrs is " + as.length);
		return as;
	}

	public String[] getUsedAttributesByDN(String s) {
		resultCode = -1;
		resultCodeString = new String("The entry is not found!");
		if (s == null || !DN.isDN(s))
			return null;
		Object obj = null;
		try {
			String s1 = "(objectclass=*)";
			LDAPSearchResults ldapsearchresults = ld.search(s, LDAPv2.SCOPE_BASE, s1, null, false);
			if (ldapsearchresults == null)
				return null;
			while (ldapsearchresults.hasMoreElements()) {
				LDAPEntry ldapentry;
				try {
					ldapentry = ldapsearchresults.next();
				} catch (LDAPReferralException ldapreferralexception) {
					System.out.println("Search references: ");
					LDAPUrl aldapurl[] = ldapreferralexception.getURLs();
					for (int i = 0; i < aldapurl.length; i++) {
						System.out.println("\t" + aldapurl[i].getUrl());
						resultCodeString = new String(ldapreferralexception.toString());
						resultCode = ldapreferralexception.getLDAPResultCode();
					}

					continue;
				} catch (LDAPException ldapexception1) {
					resultCodeString = new String(ldapexception1.toString());
					resultCode = ldapexception1.getLDAPResultCode();
					continue;
				}
				LDAPAttributeSet ldapattributeset = ldapentry.getAttributeSet();
				Enumeration enumeration = ldapattributeset.getAttributes();
				int j = 0;
				for (; enumeration.hasMoreElements(); enumeration.nextElement())
					j++;

				String as[] = new String[j];
				int k = 0;
				ldapattributeset = ldapentry.getAttributeSet();
				for (Enumeration enumeration1 = ldapattributeset.getAttributes(); enumeration1.hasMoreElements();) {
					LDAPAttribute ldapattribute = (LDAPAttribute) enumeration1.nextElement();
					as[k] = ldapattribute.getName();
					k++;
				}

				resultCodeString = new String("The number of used attrs is " + k);
				resultCode = 0;
				return as;
			}
		} catch (LDAPException ldapexception) {
			resultCodeString = new String(ldapexception.toString());
			resultCode = ldapexception.getLDAPResultCode();
		}
		return null;
	}

	public String[][] getUsedAttributesAndTypeByDN(String s) {
		resultCode = -1;
		resultCodeString = new String("The entry is not found!");
		if (s == null || !DN.isDN(s))
			return null;
		Object obj = null;
		try {
			String s1 = "(objectclass=*)";
			LDAPSearchResults ldapsearchresults = ld.search(s, LDAPv2.SCOPE_BASE, s1, null, true);
			if (ldapsearchresults == null)
				return null;
			while (ldapsearchresults.hasMoreElements()) {
				LDAPEntry ldapentry;
				try {
					ldapentry = ldapsearchresults.next();
				} catch (LDAPReferralException ldapreferralexception) {
					System.out.println("Search references: ");
					LDAPUrl aldapurl[] = ldapreferralexception.getURLs();
					for (int i = 0; i < aldapurl.length; i++) {
						System.out.println("\t" + aldapurl[i].getUrl());
						resultCodeString = new String(ldapreferralexception.toString());
						resultCode = ldapreferralexception.getLDAPResultCode();
					}

					continue;
				} catch (LDAPException ldapexception1) {
					resultCodeString = new String(ldapexception1.toString());
					resultCode = ldapexception1.getLDAPResultCode();
					continue;
				}
				LDAPAttributeSet ldapattributeset = ldapentry.getAttributeSet();
				Enumeration enumeration = ldapattributeset.getAttributes();
				int j = 0;
				for (; enumeration.hasMoreElements(); enumeration.nextElement())
					j++;

				String as[][] = new String[j][3];
				int k = 0;
				ldapattributeset = ldapentry.getAttributeSet();
				enumeration = ldapattributeset.getAttributes();
				dirSchema = new LDAPSchema();
				dirSchema.fetchSchema(ld);
				while (enumeration.hasMoreElements()) {
					LDAPAttribute ldapattribute = (LDAPAttribute) enumeration.nextElement();
					as[k][0] = ldapattribute.getName();
					LDAPAttributeSchema ldapattributeschema = dirSchema.getAttribute(as[k][0]);
					if (ldapattributeschema != null) {
						if (ldapattributeschema.isSingleValued())
							as[k][1] = new String("0");
						else
							as[k][1] = new String("1");
						as[k][2] = new String(Integer.toString(ldapattributeschema.getSyntax()));
					} else {
						resultCodeString = new String("Server-Side Error!!");
						resultCode = -1;
						return null;
					}
					k++;
				}
				resultCodeString = new String("The number of used attrs is " + k);
				resultCode = 0;
				return as;
			}
		} catch (LDAPException ldapexception) {
			resultCodeString = new String(ldapexception.toString());
			resultCode = ldapexception.getLDAPResultCode();
		}
		return null;
	}

	public void ldapAdd(String s, String as[]) {
		resultCode = -1;
		resultCodeString = new String("Adding is fail!");
		if (s == null || !DN.isDN(s) || as == null)
			return;
		LDAPAttribute aldapattribute[] = null;
		for (int i = 0; i < as.length; i++) {
			String s1 = new String(as[i]);
			int k = s1.indexOf(' ');
			if (k < 0)
				return;
			String s2 = s1.substring(0, k);
			String s3 = s1.substring(k + 1);
			if (aldapattribute == null) {
				aldapattribute = new LDAPAttribute[1];
				aldapattribute[0] = new LDAPAttribute(s2);
				aldapattribute[0].addValue(s3);
			} else {
				boolean flag = false;
				int l;
				for (l = 0; l < aldapattribute.length; l++) {
					if (!s2.equals(aldapattribute[l].getName()))
						continue;
					flag = true;
					break;
				}

				if (flag) {
					aldapattribute[l].addValue(s3);
				} else {
					LDAPAttribute aldapattribute1[] = new LDAPAttribute[aldapattribute.length + 1];
					System.arraycopy(aldapattribute, 0, aldapattribute1, 0, aldapattribute.length);
					aldapattribute1[aldapattribute.length] = new LDAPAttribute(s2);
					aldapattribute1[aldapattribute.length].addValue(s3);
					aldapattribute = aldapattribute1;
				}
			}
		}

		LDAPAttributeSet ldapattributeset = new LDAPAttributeSet();
		for (int j = 0; j < aldapattribute.length; j++)
			ldapattributeset.add(aldapattribute[j]);

		LDAPEntry ldapentry = new LDAPEntry(s, ldapattributeset);
		try {
			ld.add(ldapentry);
		} catch (LDAPException ldapexception) {
			resultCodeString = new String(ldapexception.toString());
			resultCode = ldapexception.getLDAPResultCode();
			return;
		}
		resultCodeString = new String("Adding is success!");
		resultCode = 0;
	}

	public void ldapAdd(String s, LDAPAttributeSet ldapattributeset) {
		resultCode = -1;
		resultCodeString = new String("Adding is fail!");
		if (s == null || !DN.isDN(s) || ldapattributeset == null)
			return;
		LDAPEntry ldapentry = new LDAPEntry(s, ldapattributeset);
		try {
			ld.add(ldapentry);
		} catch (LDAPException ldapexception) {
			resultCodeString = new String(ldapexception.toString());
			resultCode = ldapexception.getLDAPResultCode();
			return;
		}
		resultCodeString = new String("Adding is success!");
		resultCode = 0;
	}

	public void ldapDelete(String s) {
		resultCode = -1;
		resultCodeString = new String("Deleting is fail!");
		if (s == null || !DN.isDN(s))
			return;
		try {
			ld.delete(s);
		} catch (LDAPException ldapexception) {
			resultCodeString = new String(ldapexception.toString());
			resultCode = ldapexception.getLDAPResultCode();
			return;
		}
		resultCodeString = new String("Deleting is success!");
		resultCode = 0;
	}

	public void ldapModify(String s, LDAPModificationSet ldapmodificationset) {
		resultCode = -1;
		resultCodeString = new String("Modification is fail!");
		if (s == null || !DN.isDN(s) || ldapmodificationset == null)
			return;
		try {
			ld.modify(s, ldapmodificationset);
		} catch (LDAPException ldapexception) {
			resultCodeString = new String(ldapexception.toString());
			resultCode = ldapexception.getLDAPResultCode();
			return;
		}
		resultCodeString = new String("Modification is success!");
		resultCode = 0;
	}

	private void ldapMod(String s, String as[], int i) {
		resultCode = -1;
		resultCodeString = new String("Modifying is fail!");
		if (s == null || !DN.isDN(s))
			return;
		LDAPAttribute aldapattribute[] = null;
		for (int j = 0; j < as.length; j++) {
			String s1 = new String(as[j]);
			int l = s1.indexOf(' ');
			String s2 = null;
			String s3 = null;
			if (l < 0) {
				s2 = s1.substring(0);
				s3 = null;
			} else {
				s2 = s1.substring(0, l);
				s3 = s1.substring(l + 1);
			}
			if (aldapattribute == null) {
				aldapattribute = new LDAPAttribute[1];
				aldapattribute[0] = new LDAPAttribute(s2);
				if (s3 != null)
					aldapattribute[0].addValue(s3);
			} else {
				boolean flag = false;
				int i1;
				for (i1 = 0; i1 < aldapattribute.length; i1++) {
					if (!s2.equals(aldapattribute[i1].getName()))
						continue;
					flag = true;
					break;
				}

				if (flag) {
					if (s3 != null)
						aldapattribute[i1].addValue(s3);
				} else {
					LDAPAttribute aldapattribute1[] = new LDAPAttribute[aldapattribute.length + 1];
					System.arraycopy(aldapattribute, 0, aldapattribute1, 0, aldapattribute.length);
					aldapattribute1[aldapattribute.length] = new LDAPAttribute(s2);
					if (s3 != null)
						aldapattribute1[aldapattribute.length].addValue(s3);
					aldapattribute = aldapattribute1;
				}
			}
		}

		LDAPModificationSet ldapmodificationset = new LDAPModificationSet();
		for (int k = 0; k < aldapattribute.length; k++)
			ldapmodificationset.add(i, aldapattribute[k]);

		try {
			ld.modify(s, ldapmodificationset);
		} catch (LDAPException ldapexception) {
			resultCodeString = new String(ldapexception.toString());
			resultCode = ldapexception.getLDAPResultCode();
			return;
		}
		resultCodeString = new String("Modifying is success!");
		resultCode = 0;
	}

	public void ldapModAdd(String s, String as[]) {
		ldapMod(s, as, 0);
	}

	public void ldapModDelete(String s, String as[]) {
		ldapMod(s, as, 1);
	}

	public void ldapModReplace(String s, String as[]) {
		ldapMod(s, as, 2);
	}

	private void ldapMod(String s, String as[], byte abyte0[][], int i) {
		resultCode = -1;
		resultCodeString = new String("Modifying is fail!");
		if (s == null || !DN.isDN(s))
			return;
		LDAPAttribute aldapattribute[] = null;
		for (int j = 0; j < as.length; j++) {
			String s1 = new String(as[j]);
			byte abyte1[] = null;
			if (abyte0 != null && abyte0[j] != null)
				abyte1 = abyte0[j];
			if (aldapattribute == null) {
				aldapattribute = new LDAPAttribute[1];
				aldapattribute[0] = new LDAPAttribute(s1);
				if (abyte1 != null)
					aldapattribute[0].addValue(abyte1);
			} else {
				boolean flag = false;
				int l;
				for (l = 0; l < aldapattribute.length; l++) {
					if (!s1.equals(aldapattribute[l].getName()))
						continue;
					flag = true;
					break;
				}

				if (flag) {
					if (abyte1 != null)
						aldapattribute[l].addValue(abyte1);
				} else {
					LDAPAttribute aldapattribute1[] = new LDAPAttribute[aldapattribute.length + 1];
					System.arraycopy(aldapattribute, 0, aldapattribute1, 0, aldapattribute.length);
					aldapattribute1[aldapattribute.length] = new LDAPAttribute(s1);
					if (abyte1 != null)
						aldapattribute1[aldapattribute.length].addValue(abyte1);
					aldapattribute = aldapattribute1;
				}
			}
		}

		LDAPModificationSet ldapmodificationset = new LDAPModificationSet();
		for (int k = 0; k < aldapattribute.length; k++)
			ldapmodificationset.add(i, aldapattribute[k]);

		try {
			ld.modify(s, ldapmodificationset);
		} catch (LDAPException ldapexception) {
			resultCodeString = new String(ldapexception.toString());
			resultCode = ldapexception.getLDAPResultCode();
			return;
		}
		resultCodeString = new String("Modifying is success!");
		resultCode = 0;
	}

	public void ldapModAdd(String s, String as[], byte abyte0[][]) {
		ldapMod(s, as, abyte0, 0);
	}

	public void ldapModDelete(String s, String as[], byte abyte0[][]) {
		ldapMod(s, as, abyte0, 1);
	}

	public void ldapModReplace(String s, String as[], byte abyte0[][]) {
		ldapMod(s, as, abyte0, 2);
	}

	public String[] getChildDNs(String s) {
		resultCode = -1;
		resultCodeString = new String("This DN is the Leaf Node, or Insufficient right");
		Object obj = null;
		Object obj1 = null;
		Vector vector = new Vector();
		String as[] = null;
		int i = 0;
		if (s == null || s.length() < 1)
			return null;
		try {
			String s1 = "(objectclass=*)";
			String as1[] = new String[1];
			as1[0] = new String("LDAPv3.NO_ATTRS");
			LDAPSearchResults ldapsearchresults = ld.search(s, LDAPv2.SCOPE_ONE, s1, as1, true);
			if (ldapsearchresults == null)
				return null;
			while (ldapsearchresults.hasMoreElements()) {
				LDAPEntry ldapentry;
				try {
					ldapentry = ldapsearchresults.next();
				} catch (LDAPReferralException ldapreferralexception) {
					continue;
				} catch (LDAPException ldapexception1) {
					resultCodeString = new String(ldapexception1.toString());
					resultCode = ldapexception1.getLDAPResultCode();
					return null;
				}
				vector.add(ldapentry.getDN());
			}
		} catch (LDAPException ldapexception) {
			resultCodeString = new String(ldapexception.toString());
			resultCode = ldapexception.getLDAPResultCode();
			return null;
		}
		if (vector.size() == 0)
			return null;
		i = vector.size();
		as = new String[i];
		for (int j = 0; j < i; j++)
			as[j] = (String) vector.get(j);

		resultCode = 0;
		resultCodeString = new String("Search is successful!");
		return as;
	}

	public boolean hasChild(String s) {
		resultCode = -1;
		resultCodeString = new String("No child exist");
		if (s == null || s.length() < 1)
			return false;
		try {
			String s1 = "(objectclass=*)";
			String as[] = new String[1];
			as[0] = new String("LDAPv3.NO_ATTRS");
			LDAPSearchResults ldapsearchresults = null;
			ld.setOption(LDAPv2.SIZELIMIT, new Integer(1));
			ldapsearchresults = ld.search(s, 1, s1, as, true);
			ld.setOption(LDAPv2.SIZELIMIT, new Integer(0));
			if ((ldapsearchresults != null) & ldapsearchresults.hasMoreElements()) {
				resultCode = 0;
				resultCodeString = new String("Child exists");
				return true;
			}
		} catch (LDAPException ldapexception) {
			resultCodeString = new String(ldapexception.toString());
			resultCode = ldapexception.getLDAPResultCode();
			return false;
		}
		return false;
	}

	public boolean hasChilds(String s) {
		resultCode = -1;
		resultCodeString = new String("No child exists");
		Object obj = null;
		Object obj1 = null;
		int i = 0;
		LDAPSearchConstraints ldapsearchconstraints = ld.getSearchConstraints();
		ldapsearchconstraints.setMaxResults(5);
		if (s == null || s.length() < 1)
			return false;
		try {
			String s1 = "(objectclass=*)";
			String as[] = new String[1];
			as[0] = new String("LDAPv3.NO_ATTRS");
			LDAPSearchResults ldapsearchresults = ld.search(s, LDAPv2.SCOPE_ONE, s1, as, false, ldapsearchconstraints);
			if (ldapsearchresults == null)
				return false;
			while (ldapsearchresults.hasMoreElements()) {
				LDAPEntry ldapentry;
				try {
					ldapentry = ldapsearchresults.next();
				} catch (LDAPReferralException ldapreferralexception) {
					continue;
				} catch (LDAPException ldapexception1) {
					resultCodeString = new String(ldapexception1.toString());
					resultCode = ldapexception1.getLDAPResultCode();
					return false;
				}
				i++;
			}
		} catch (LDAPException ldapexception) {
			resultCodeString = new String(ldapexception.toString());
			resultCode = ldapexception.getLDAPResultCode();
			return false;
		}
		if (i > 0) {
			System.out.println(i);
			resultCode = 0;
			resultCodeString = new String("Childs exist");
			return true;
		} else {
			return false;
		}
	}

	public String[] getRequiredAttributes(String s) {
		resultCode = -1;
		resultCodeString = new String("The object is not found!");
		Object obj = null;
		String as[] = null;
		Object obj1 = null;
		Vector vector = new Vector();
		try {
			dirSchema = new LDAPSchema();
			dirSchema.fetchSchema(ld);
			for (LDAPObjectClassSchema ldapobjectclassschema = dirSchema.getObjectClass(s); ldapobjectclassschema != null; ldapobjectclassschema = dirSchema
					.getObjectClass(ldapobjectclassschema.getSuperior())) {
				for (Enumeration enumeration = ldapobjectclassschema.getRequiredAttributes(); enumeration.hasMoreElements();) {
					String s1 = (String) enumeration.nextElement();
					if (!vector.contains(s1))
						vector.add(s1);
				}

				if (ldapobjectclassschema.getName().equalsIgnoreCase("top"))
					break;
			}

		} catch (LDAPException ldapexception) {
			resultCodeString = new String(ldapexception.toString());
			resultCode = ldapexception.getLDAPResultCode();
		}
		if (vector.size() < 1)
			return null;
		as = new String[vector.size()];
		for (int i = 0; i < vector.size(); i++)
			as[i] = new String((String) vector.get(i));

		resultCodeString = new String("The number of required attrs is " + as.length);
		resultCode = 0;
		Arrays.sort(as);
		return as;
	}

	public String[][] getRequiredAttributesAndType(String s) {
		resultCode = -1;
		resultCodeString = new String("The object is not found!");
		Object obj = null;
		Object obj1 = null;
		Vector vector = new Vector();
		Vector vector1 = new Vector();
		try {
			dirSchema = new LDAPSchema();
			dirSchema.fetchSchema(ld);
			for (LDAPObjectClassSchema ldapobjectclassschema = dirSchema.getObjectClass(s); ldapobjectclassschema != null; ldapobjectclassschema = dirSchema
					.getObjectClass(ldapobjectclassschema.getSuperior())) {
				for (Enumeration enumeration = ldapobjectclassschema.getRequiredAttributes(); enumeration.hasMoreElements();) {
					String s1 = (String) enumeration.nextElement();
					LDAPAttributeSchema ldapattributeschema = dirSchema.getAttribute(s1);
					if (ldapattributeschema != null) {
						if (!vector1.contains(s1)) {
							String as1[] = new String[3];
							as1[0] = new String(s1);
							if (ldapattributeschema.isSingleValued())
								as1[1] = new String("0");
							else
								as1[1] = new String("1");
							as1[2] = new String(Integer.toString(ldapattributeschema.getSyntax()));
							vector.add(as1);
							vector1.add(s1);
						}
					} else {
						resultCodeString = new String("Server-Side Error!!");
						resultCode = -1;
						return null;
					}
				}

				if (ldapobjectclassschema.getName().equalsIgnoreCase("top"))
					break;
			}

		} catch (LDAPException ldapexception) {
			resultCodeString = new String(ldapexception.toString());
			resultCode = ldapexception.getLDAPResultCode();
			return null;
		}
		if (vector.size() != 0) {
			resultCode = 0;
			resultCodeString = new String("The number of Required attrs is " + vector.size());
			String as[][] = new String[vector.size()][3];
			for (int i = 0; i < as.length; i++) {
				String as2[] = (String[]) vector.get(i);
				as[i][0] = new String(as2[0]);
				as[i][1] = new String(as2[1]);
				as[i][2] = new String(as2[2]);
			}

			return as;
		} else {
			return null;
		}
	}

	public String[][] getRequiredAttributesAndTypeByDN(String s) {
		resultCode = -1;
		resultCodeString = new String("The entry is not found!");
		String as[] = getMultiStringValuesByDN("objectclass", s);
		if (resultCode != 0)
			return null;
		Object obj = null;
		Object obj1 = null;
		Vector vector = new Vector();
		Vector vector1 = new Vector();
		try {
			dirSchema = new LDAPSchema();
			dirSchema.fetchSchema(ld);
			for (int i = 0; i < as.length; i++) {
				LDAPObjectClassSchema ldapobjectclassschema = dirSchema.getObjectClass(as[i]);
				if (ldapobjectclassschema != null) {
					for (Enumeration enumeration = ldapobjectclassschema.getRequiredAttributes(); enumeration.hasMoreElements();) {
						String s1 = (String) enumeration.nextElement();
						LDAPAttributeSchema ldapattributeschema = dirSchema.getAttribute(s1);
						if (ldapattributeschema != null) {
							if (!vector1.contains(s1)) {
								String as2[] = new String[3];
								as2[0] = new String(s1);
								if (ldapattributeschema.isSingleValued())
									as2[1] = new String("0");
								else
									as2[1] = new String("1");
								as2[2] = new String(Integer.toString(ldapattributeschema.getSyntax()));
								vector.add(as2);
								vector1.add(s1);
							}
						} else {
							resultCodeString = new String("Server-Side Error!!");
							resultCode = -1;
							return null;
						}
					}

				}
			}

		} catch (LDAPException ldapexception) {
			resultCodeString = new String(ldapexception.toString());
			resultCode = ldapexception.getLDAPResultCode();
			return null;
		}
		if (vector.size() != 0) {
			resultCode = 0;
			resultCodeString = new String("The number of Required attrs is " + vector.size());
			String as1[][] = new String[vector.size()][3];
			for (int j = 0; j < as1.length; j++) {
				String as3[] = (String[]) vector.get(j);
				as1[j][0] = new String(as3[0]);
				as1[j][1] = new String(as3[1]);
				as1[j][2] = new String(as3[2]);
			}

			return as1;
		} else {
			resultCode = -1;
			resultCodeString = new String("The entry is not found!");
			return null;
		}
	}

	public String[][] getOptionalAttributesAndType(String s) {
		resultCode = -1;
		resultCodeString = new String("The object is not found!");
		Object obj = null;
		Object obj1 = null;
		Vector vector = new Vector();
		Vector vector1 = new Vector();
		try {
			dirSchema = new LDAPSchema();
			dirSchema.fetchSchema(ld);
			for (LDAPObjectClassSchema ldapobjectclassschema = dirSchema.getObjectClass(s); ldapobjectclassschema != null; ldapobjectclassschema = dirSchema
					.getObjectClass(ldapobjectclassschema.getSuperior())) {
				for (Enumeration enumeration = ldapobjectclassschema.getOptionalAttributes(); enumeration.hasMoreElements();) {
					String s1 = (String) enumeration.nextElement();
					LDAPAttributeSchema ldapattributeschema = dirSchema.getAttribute(s1);
					if (ldapattributeschema != null) {
						if (!vector1.contains(s1)) {
							String as1[] = new String[3];
							as1[0] = new String(s1);
							if (ldapattributeschema.isSingleValued())
								as1[1] = new String("0");
							else
								as1[1] = new String("1");
							as1[2] = new String(Integer.toString(ldapattributeschema.getSyntax()));
							vector.add(as1);
							vector1.add(s1);
						}
					} else {
						resultCodeString = new String("Server-Side Error!!");
						resultCode = -1;
						return null;
					}
				}

				if (ldapobjectclassschema.getName().equalsIgnoreCase("top"))
					break;
			}

		} catch (LDAPException ldapexception) {
			resultCodeString = new String(ldapexception.toString());
			resultCode = ldapexception.getLDAPResultCode();
			return null;
		}
		if (vector.size() != 0) {
			resultCode = 0;
			resultCodeString = new String("The number of optional attrs is " + vector.size());
			String as[][] = new String[vector.size()][3];
			for (int i = 0; i < as.length; i++) {
				String as2[] = (String[]) vector.get(i);
				as[i][0] = new String(as2[0]);
				as[i][1] = new String(as2[1]);
				as[i][2] = new String(as2[2]);
			}

			return as;
		} else {
			return null;
		}
	}

	public String[][] getOptionalAttributesAndTypeByDN(String s) {
		resultCode = -1;
		resultCodeString = new String("The entry not found!");
		String as[] = getMultiStringValuesByDN("objectclass", s);
		if (resultCode != 0)
			return null;
		Object obj = null;
		Object obj1 = null;
		Vector vector = new Vector();
		Vector vector1 = new Vector();
		try {
			dirSchema = new LDAPSchema();
			dirSchema.fetchSchema(ld);
			for (int i = 0; i < as.length; i++) {
				LDAPObjectClassSchema ldapobjectclassschema = dirSchema.getObjectClass(as[i]);
				if (ldapobjectclassschema != null) {
					for (Enumeration enumeration = ldapobjectclassschema.getOptionalAttributes(); enumeration.hasMoreElements();) {
						String s1 = (String) enumeration.nextElement();
						LDAPAttributeSchema ldapattributeschema = dirSchema.getAttribute(s1);
						if (ldapattributeschema != null) {
							if (!vector1.contains(s1)) {
								String as2[] = new String[3];
								as2[0] = new String(s1);
								if (ldapattributeschema.isSingleValued())
									as2[1] = new String("0");
								else
									as2[1] = new String("1");
								as2[2] = new String(Integer.toString(ldapattributeschema.getSyntax()));
								vector.add(as2);
								vector1.add(s1);
							}
						} else {
							resultCodeString = new String("Server-Side Error!!");
							resultCode = -1;
							return null;
						}
					}

				}
			}

		} catch (LDAPException ldapexception) {
			resultCodeString = new String(ldapexception.toString());
			resultCode = ldapexception.getLDAPResultCode();
			return null;
		}
		if (vector.size() > 0) {
			resultCode = 0;
			resultCodeString = new String("The number of optional attrs is " + vector.size());
			String as1[][] = new String[vector.size()][3];
			for (int j = 0; j < as1.length; j++) {
				String as3[] = (String[]) vector.get(j);
				as1[j][0] = new String(as3[0]);
				as1[j][1] = new String(as3[1]);
				as1[j][2] = new String(as3[2]);
			}

			return as1;
		} else {
			resultCode = -1;
			resultCodeString = new String("The entry is not found!");
			return null;
		}
	}

	public String[] getOptionalAttributes(String s) {
		resultCode = -1;
		resultCodeString = new String("The object is not found!");
		boolean flag = false;
		Object obj = null;
		String as[] = null;
		Object obj1 = null;
		Vector vector = new Vector();
		try {
			dirSchema = new LDAPSchema();
			dirSchema.fetchSchema(ld);
			for (LDAPObjectClassSchema ldapobjectclassschema = dirSchema.getObjectClass(s); ldapobjectclassschema != null; ldapobjectclassschema = dirSchema
					.getObjectClass(ldapobjectclassschema.getSuperior())) {
				for (Enumeration enumeration = ldapobjectclassschema.getOptionalAttributes(); enumeration.hasMoreElements();) {
					String s1 = (String) enumeration.nextElement();
					if (!vector.contains(s1))
						vector.add(s1);
				}

				if (ldapobjectclassschema.getName().equalsIgnoreCase("top"))
					break;
			}

		} catch (LDAPException ldapexception) {
			resultCodeString = new String(ldapexception.toString());
			resultCode = ldapexception.getLDAPResultCode();
			return null;
		}
		if (vector.size() < 1)
			return null;
		as = new String[vector.size()];
		for (int i = 0; i < vector.size(); i++)
			as[i] = new String((String) vector.get(i));

		resultCodeString = new String("The number of optional attrs is " + as.length);
		resultCode = 0;
		Arrays.sort(as);
		return as;
	}

	public String[] getAllObjectClasses() {
		resultCode = -1;
		resultCodeString = new String("Server Error!");
		String as[] = null;
		Vector vector = new Vector();
		Object obj = null;
		try {
			dirSchema = new LDAPSchema();
			dirSchema.fetchSchema(ld);
			String s;
			for (Enumeration enumeration = dirSchema.getObjectClassNames(); enumeration.hasMoreElements(); vector.add(s))
				s = (String) enumeration.nextElement();

		} catch (LDAPException ldapexception) {
			resultCodeString = new String(ldapexception.toString());
			resultCode = -1;
			return null;
		}
		if (vector.size() < 1)
			return null;
		as = new String[vector.size()];
		for (int i = 0; i < vector.size(); i++)
			as[i] = (String) vector.get(i);

		resultCode = 0;
		resultCodeString = new String("The number of total objects is: " + as.length);
		Arrays.sort(as);
		return as;
	}

	public String[] getAllAttributes() {
		resultCode = -1;
		resultCodeString = new String("Server Error!");
		boolean flag = false;
		String as[] = null;
		Vector vector = new Vector();
		Object obj = null;
		try {
			dirSchema = new LDAPSchema();
			dirSchema.fetchSchema(ld);
			String s;
			for (Enumeration enumeration = dirSchema.getAttributeNames(); enumeration.hasMoreElements(); vector.add(s))
				s = (String) enumeration.nextElement();

		} catch (LDAPException ldapexception) {
			resultCodeString = new String(ldapexception.toString());
			resultCode = -1;
			return null;
		}
		if (vector.size() < 1)
			return null;
		as = new String[vector.size()];
		for (int i = 0; i < vector.size(); i++)
			as[i] = (String) vector.get(i);

		resultCode = 0;
		resultCodeString = new String("The number of total attributes is: " + as.length);
		Arrays.sort(as);
		return as;
	}

	public String[][] getAllAttrAndType() {
		resultCode = -1;
		resultCodeString = new String("Server Error!");
		boolean flag = false;
		String as[][] = null;
		Object obj = null;
		String as1[] = null;
		Vector vector = new Vector();
		try {
			dirSchema = new LDAPSchema();
			dirSchema.fetchSchema(ld);
			String s;
			for (Enumeration enumeration = dirSchema.getAttributeNames(); enumeration.hasMoreElements(); vector.add(s))
				s = new String((String) enumeration.nextElement());

		} catch (LDAPException ldapexception) {
			resultCodeString = new String(ldapexception.toString());
			resultCode = -1;
			return null;
		}
		if (vector.size() < 1)
			return null;
		as = new String[vector.size()][2];
		as1 = new String[vector.size()];
		for (int i = 0; i < vector.size(); i++)
			as1[i] = (String) vector.get(i);

		Arrays.sort(as1);
		for (int j = 0; j < as1.length; j++) {
			as[j][0] = new String(as1[j]);
			String s1 = dirSchema.getAttribute(as1[j]).getDescription();
			if (s1 != null && s1.length() > 0 && s1.equals("User Defined Attribute"))
				as[j][1] = new String("0");
			else
				as[j][1] = new String("1");
		}

		resultCode = 0;
		resultCodeString = new String("The number of total attributes is: " + as.length);
		return as;
	}

	public boolean isSingleValued(String s) {
		resultCode = -1;
		resultCodeString = new String("The assigned attribute is wrong!!");
		try {
			dirSchema = new LDAPSchema();
			dirSchema.fetchSchema(ld);
			LDAPAttributeSchema ldapattributeschema = dirSchema.getAttribute(s);
			if (ldapattributeschema != null) {
				if (ldapattributeschema.isSingleValued())
					resultCodeString = new String("It's Single-Value");
				else
					resultCodeString = new String("It's Multi-Value");
				resultCode = 0;
				return ldapattributeschema.isSingleValued();
			} else {
				resultCodeString = new String("The assigned attribute is wrong!!");
				resultCode = -1;
				return false;
			}
		} catch (LDAPException ldapexception) {
			resultCodeString = new String(ldapexception.toString());
			resultCode = ldapexception.getLDAPResultCode();
			return false;
		}
	}

	public String[] getSuperiors(String s) {
		resultCode = -1;
		resultCodeString = new String("The Objectclass name is wrong!!");
		int i = 0;
		Object obj = null;
		try {
			dirSchema = new LDAPSchema();
			dirSchema.fetchSchema(ld);
			LDAPObjectClassSchema ldapobjectclassschema = dirSchema.getObjectClass(s);
			if (ldapobjectclassschema != null) {
				String as[] = new String[1];
				as[0] = new String(s);
				i++;
				LDAPObjectClassSchema ldapobjectclassschema1;
				for (String s1 = new String(s); !s1.equalsIgnoreCase("top"); s1 = ldapobjectclassschema1.getSuperior()) {
					ldapobjectclassschema1 = dirSchema.getObjectClass(s1);
					String as1[] = new String[++i];
					for (int j = 0; j < i - 1; j++)
						as1[j] = new String(as[j]);

					as1[i - 1] = new String(ldapobjectclassschema1.getSuperior());
					as = as1;
				}

				resultCode = 0;
				resultCodeString = new String("The number of total superiors is: " + i);
				return as;
			} else {
				resultCode = -1;
				resultCodeString = new String("The Objectclass name is wrong!!");
				return null;
			}
		} catch (LDAPException ldapexception) {
			resultCodeString = new String(ldapexception.toString());
			resultCode = ldapexception.getLDAPResultCode();
			return null;
		}
	}

	public boolean isStandardAttribute(String s) {
		resultCode = -1;
		resultCodeString = new String("The assigned attribute is wrong!!");
		try {
			dirSchema = new LDAPSchema();
			dirSchema.fetchSchema(ld);
			LDAPAttributeSchema ldapattributeschema = dirSchema.getAttribute(s);
			if (ldapattributeschema != null) {
				if (!ldapattributeschema.getDescription().equals("User Defined Attribute"))
					resultCodeString = new String("It's a Standard Attribute");
				else
					resultCodeString = new String("It's a User Defined Attribute");
				resultCode = 0;
				return !ldapattributeschema.getDescription().equals("User Defined Attribute");
			} else {
				resultCodeString = new String("The assigned attribute is wrong!!");
				resultCode = -1;
				return false;
			}
		} catch (LDAPException ldapexception) {
			resultCodeString = new String(ldapexception.toString());
			resultCode = ldapexception.getLDAPResultCode();
			return false;
		}
	}

	public String getAttributeOID(String s) {
		resultCode = -1;
		resultCodeString = new String("The assigned attribute is wrong!!");
		try {
			dirSchema = new LDAPSchema();
			dirSchema.fetchSchema(ld);
			LDAPAttributeSchema ldapattributeschema = dirSchema.getAttribute(s);
			if (ldapattributeschema != null) {
				resultCode = 0;
				return ldapattributeschema.getOID();
			} else {
				resultCodeString = new String("The assigned attribute is wrong!!");
				resultCode = -1;
				return null;
			}
		} catch (LDAPException ldapexception) {
			resultCodeString = new String(ldapexception.toString());
			resultCode = ldapexception.getLDAPResultCode();
			return null;
		}
	}

	public String getObjectClassOID(String s) {
		resultCode = -1;
		resultCodeString = new String("The assigned objectclass is wrong!!");
		try {
			dirSchema = new LDAPSchema();
			dirSchema.fetchSchema(ld);
			LDAPObjectClassSchema ldapobjectclassschema = dirSchema.getObjectClass(s);
			if (ldapobjectclassschema != null) {
				resultCode = 0;
				return ldapobjectclassschema.getOID();
			} else {
				resultCodeString = new String("The assigned objectclass is wrong!!");
				resultCode = -1;
				return null;
			}
		} catch (LDAPException ldapexception) {
			resultCodeString = new String(ldapexception.toString());
			resultCode = ldapexception.getLDAPResultCode();
			return null;
		}
	}

	public String getObjectClassSuperior(String s) {
		resultCode = -1;
		resultCodeString = new String("The assigned objectclass is wrong!!");
		try {
			dirSchema = new LDAPSchema();
			dirSchema.fetchSchema(ld);
			LDAPObjectClassSchema ldapobjectclassschema = dirSchema.getObjectClass(s);
			if (ldapobjectclassschema != null) {
				resultCode = 0;
				return ldapobjectclassschema.getSuperior();
			} else {
				resultCodeString = new String("The assigned objectclass is wrong!!");
				resultCode = -1;
				return null;
			}
		} catch (LDAPException ldapexception) {
			resultCodeString = new String(ldapexception.toString());
			resultCode = ldapexception.getLDAPResultCode();
			return null;
		}
	}

	public String[] getObjectClassSuperiors(String s) {
		resultCode = -1;
		resultCodeString = new String("The assigned objectclass is wrong!!");
		try {
			dirSchema = new LDAPSchema();
			dirSchema.fetchSchema(ld);
			LDAPObjectClassSchema ldapobjectclassschema = dirSchema.getObjectClass(s);
			if (ldapobjectclassschema != null) {
				resultCode = 0;
				return ldapobjectclassschema.getSuperiors();
			} else {
				resultCodeString = new String("The assigned objectclass is wrong!!");
				resultCode = -1;
				return null;
			}
		} catch (LDAPException ldapexception) {
			resultCodeString = new String(ldapexception.toString());
			resultCode = ldapexception.getLDAPResultCode();
			return null;
		}
	}

	public String getObjectClassDescription(String s) {
		resultCode = -1;
		resultCodeString = new String("The assigned objectclass is wrong!!");
		try {
			dirSchema = new LDAPSchema();
			dirSchema.fetchSchema(ld);
			LDAPObjectClassSchema ldapobjectclassschema = dirSchema.getObjectClass(s);
			if (ldapobjectclassschema != null) {
				resultCode = 0;
				return ldapobjectclassschema.getDescription();
			} else {
				resultCodeString = new String("The assigned objectclass is wrong!!");
				resultCode = -1;
				return null;
			}
		} catch (LDAPException ldapexception) {
			resultCodeString = new String(ldapexception.toString());
			resultCode = ldapexception.getLDAPResultCode();
			return null;
		}
	}

	public String getAttributeDescription(String s) {
		resultCode = -1;
		resultCodeString = new String("The assigned attribute is wrong!!");
		try {
			dirSchema = new LDAPSchema();
			dirSchema.fetchSchema(ld);
			LDAPAttributeSchema ldapattributeschema = dirSchema.getAttribute(s);
			if (ldapattributeschema != null) {
				resultCode = 0;
				return ldapattributeschema.getDescription();
			} else {
				resultCodeString = new String("The assigned attribute is wrong!!");
				resultCode = -1;
				return null;
			}
		} catch (LDAPException ldapexception) {
			resultCodeString = new String(ldapexception.toString());
			resultCode = ldapexception.getLDAPResultCode();
			return null;
		}
	}

	public int getAttributeSyntax(String s) {
		resultCode = -1;
		resultCodeString = new String("The assigned attribute is wrong!!");
		try {
			dirSchema = new LDAPSchema();
			dirSchema.fetchSchema(ld);
			LDAPAttributeSchema ldapattributeschema = dirSchema.getAttribute(s);
			if (ldapattributeschema != null) {
				resultCode = 0;
				return ldapattributeschema.getSyntax();
			} else {
				resultCodeString = new String("The assigned attribute is wrong!!");
				resultCode = -1;
				return -1;
			}
		} catch (LDAPException ldapexception) {
			resultCodeString = new String(ldapexception.toString());
			resultCode = ldapexception.getLDAPResultCode();
			return -1;
		}
	}

	public boolean isBinaryType(String s) {
		resultCode = -1;
		resultCodeString = new String("The assigned attribute is wrong!!");
		try {
			dirSchema = new LDAPSchema();
			dirSchema.fetchSchema(ld);
			LDAPAttributeSchema ldapattributeschema = dirSchema.getAttribute(s);
			if (ldapattributeschema != null) {
				if (ldapattributeschema.getSyntax() == 2) {
					resultCodeString = new String("It's binary type");
					resultCode = 0;
					return true;
				} else {
					resultCodeString = new String("It's not binary type");
					resultCode = 0;
					return false;
				}
			} else {
				resultCodeString = new String("The assigned attribute is wrong!!");
				resultCode = -1;
				return false;
			}
		} catch (LDAPException ldapexception) {
			resultCodeString = new String(ldapexception.toString());
			resultCode = ldapexception.getLDAPResultCode();
			return false;
		}
	}

	public void addAttribute(String s, String s1, String s2, int i, boolean flag) {
		resultCode = -1;
		resultCodeString = new String("The adding is fail!");
		LDAPAttributeSchema ldapattributeschema = new LDAPAttributeSchema(s, s1, s2, i, flag);
		if (ldapattributeschema == null)
			return;
		try {
			dirSchema = new LDAPSchema();
			dirSchema.fetchSchema(ld);
			ldapattributeschema.add(ld);
		} catch (LDAPException ldapexception) {
			resultCodeString = new String(ldapexception.toString());
			resultCode = ldapexception.getLDAPResultCode();
			return;
		}
		resultCode = 0;
		resultCodeString = new String("The adding is successful! ");
	}

	public void removeAttribute(String s) {
		resultCode = -1;
		resultCodeString = new String("The removing is fail!");
		try {
			dirSchema = new LDAPSchema();
			dirSchema.fetchSchema(ld);
			LDAPAttributeSchema ldapattributeschema = dirSchema.getAttribute(s);
			if (ldapattributeschema == null)
				return;
			ldapattributeschema.remove(ld);
		} catch (LDAPException ldapexception) {
			resultCodeString = new String(ldapexception.toString());
			resultCode = ldapexception.getLDAPResultCode();
			return;
		}
		resultCode = 0;
		resultCodeString = new String("The removing is successful! ");
	}

	public void modifyAttribute(String s, String s1, String s2, String s3, int i, boolean flag) {
		resultCode = -1;
		resultCodeString = new String("The modification is fail!");
		try {
			LDAPAttributeSchema ldapattributeschema = new LDAPAttributeSchema(s1, s2, s3, i, flag);
			if (ldapattributeschema == null)
				return;
			dirSchema = new LDAPSchema();
			dirSchema.fetchSchema(ld);
			LDAPAttributeSchema ldapattributeschema1 = dirSchema.getAttribute(s);
			if (ldapattributeschema1 == null)
				return;
			ldapattributeschema1.modify(ld, ldapattributeschema);
		} catch (LDAPException ldapexception) {
			resultCodeString = new String(ldapexception.toString());
			resultCode = ldapexception.getLDAPResultCode();
			return;
		}
		resultCode = 0;
		resultCodeString = new String("The modification is successful! ");
	}

	public String[][] getAllObjAndType() {
		resultCode = -1;
		resultCodeString = new String("Server Error!");
		Object obj = null;
		Object obj1 = null;
		Object obj2 = null;
		Vector vector = new Vector();
		try {
			dirSchema = new LDAPSchema();
			dirSchema.fetchSchema(ld);
			String s;
			for (Enumeration enumeration = dirSchema.getObjectClassNames(); enumeration.hasMoreElements(); vector.add(s))
				s = (String) enumeration.nextElement();

			if (vector.size() > 0) {
				String as1[] = new String[vector.size()];
				for (int i = 0; i < vector.size(); i++)
					as1[i] = new String((String) vector.get(i));

				Arrays.sort(as1);
				String as[][] = new String[as1.length][2];
				for (int j = 0; j < as1.length; j++) {
					as[j][0] = new String(as1[j]);
					String s1 = dirSchema.getObjectClass(as1[j]).getDescription();
					if (s1 != null && s1.length() > 0 && s1.equals("User Defined ObjectClass"))
						as[j][1] = new String("0");
					else
						as[j][1] = new String("1");
				}

				resultCode = 0;
				resultCodeString = new String("The number of total objectclasses is: " + as1.length);
				return as;
			}
		} catch (LDAPException ldapexception) {
			resultCodeString = new String(ldapexception.toString());
			resultCode = -1;
			return null;
		}
		return null;
	}

	public void addObjectClass(String s, String s1, String s2, String s3, String as[], String as1[]) {
		resultCode = -1;
		resultCodeString = new String("The adding is fail!");
		LDAPObjectClassSchema ldapobjectclassschema = new LDAPObjectClassSchema(s, s1, s2, s3, as, as1);
		if (ldapobjectclassschema == null)
			return;
		try {
			dirSchema = new LDAPSchema();
			dirSchema.fetchSchema(ld);
			ldapobjectclassschema.add(ld);
		} catch (LDAPException ldapexception) {
			resultCodeString = new String(ldapexception.toString());
			resultCode = ldapexception.getLDAPResultCode();
			return;
		}
		resultCode = 0;
		resultCodeString = new String("The adding is successful! ");
	}

	public void removeObjectClass(String s) {
		resultCode = -1;
		resultCodeString = new String("The removing is fail!");
		try {
			dirSchema = new LDAPSchema();
			dirSchema.fetchSchema(ld);
			LDAPObjectClassSchema ldapobjectclassschema = dirSchema.getObjectClass(s);
			if (ldapobjectclassschema == null)
				return;
			ldapobjectclassschema.remove(ld);
		} catch (LDAPException ldapexception) {
			resultCodeString = new String(ldapexception.toString());
			resultCode = ldapexception.getLDAPResultCode();
			return;
		}
		resultCode = 0;
		resultCodeString = new String("The removing is successful! ");
	}

	public void modifyObjectClass(String s, String s1, String s2, String s3, String s4, String as[], String as1[]) {
		resultCode = -1;
		resultCodeString = new String("The modification is fail!");
		try {
			LDAPObjectClassSchema ldapobjectclassschema = new LDAPObjectClassSchema(s1, s2, s3, s4, as, as1);
			if (ldapobjectclassschema == null)
				return;
			dirSchema = new LDAPSchema();
			dirSchema.fetchSchema(ld);
			LDAPObjectClassSchema ldapobjectclassschema1 = dirSchema.getObjectClass(s);
			if (ldapobjectclassschema1 == null)
				return;
			ldapobjectclassschema1.modify(ld, ldapobjectclassschema);
		} catch (LDAPException ldapexception) {
			resultCodeString = new String(ldapexception.toString());
			resultCode = ldapexception.getLDAPResultCode();
			return;
		}
		resultCode = 0;
		resultCodeString = new String("The modification is successful! ");
	}

	public boolean checkByKeyAndPwd(String s, String s1, String s2) {
		if (s == null || s.length() < 1) {
			resultCodeString = new String("The Key_Name is empty!");
			resultCode = -1;
			return false;
		}
		if (s1 == null || s1.length() < 1) {
			resultCodeString = new String("The Key_Value is empty!");
			resultCode = -1;
			return false;
		}
		if (s2 == null || s2.length() < 1) {
			resultCodeString = new String("The PASSOWRD is empty!");
			resultCode = -1;
			return false;
		}
		String as[] = getDNsByKey(s, s1);
		if (resultCode != 0) {
			resultCodeString = new String(getResultCodeString());
			return false;
		}
		String s3 = ld.getAuthenticationDN();
		String s4 = ld.getAuthenticationPassword();
		for (int i = 0; i < as.length; i++) {
			authenticate(as[i], s2);
			if (resultCode == 0) {
				resultCodeString = new String("The Authenticate is successful!");
				authenticate(s3, s4);
				return true;
			}
		}

		authenticate(s3, s4);
		return false;
	}

	private static byte[] concatenate(byte abyte0[], byte abyte1[]) {
		byte abyte2[] = new byte[abyte0.length + abyte1.length];
		System.arraycopy(abyte0, 0, abyte2, 0, abyte0.length);
		System.arraycopy(abyte1, 0, abyte2, abyte0.length, abyte1.length);
		return abyte2;
	}

	private static byte[][] split(byte abyte0[], int i) {
		byte abyte1[];
		byte abyte2[];
		if (abyte0.length <= i) {
			abyte1 = abyte0;
			abyte2 = new byte[0];
		} else {
			abyte1 = new byte[i];
			abyte2 = new byte[abyte0.length - i];
			System.arraycopy(abyte0, 0, abyte1, 0, i);
			System.arraycopy(abyte0, i, abyte2, 0, abyte2.length);
		}
		byte abyte3[][] = { abyte1, abyte2 };
		return abyte3;
	}

	private static String toHex(byte abyte0[]) {
		StringBuffer stringbuffer = new StringBuffer();
		for (int i = 0; i < abyte0.length; i++) {
			stringbuffer.append(hexits.charAt(abyte0[i] >>> 4 & 0xf));
			stringbuffer.append(hexits.charAt(abyte0[i] & 0xf));
		}

		return stringbuffer + "";
	}

	private static byte[] fromHex(String s) {
		s = s.toLowerCase();
		byte abyte0[] = new byte[(s.length() + 1) / 2];
		int i = 0;
		int k = -1;
		for (int l = 0; l < s.length(); l++) {
			int j = hexits.indexOf(s.charAt(l));
			if (j >= 0)
				if (k < 0) {
					k = j;
				} else {
					abyte0[i++] = (byte) ((k << 4) + j);
					k = -1;
				}
		}

		if (k >= 0)
			abyte0[i++] = (byte) (k << 4);
		if (i < abyte0.length) {
			byte abyte1[] = new byte[i];
			System.arraycopy(abyte0, 0, abyte1, 0, i);
			abyte0 = abyte1;
		}
		return abyte0;
	}

	public String SHA(String s) throws IOException, NoSuchAlgorithmException {
		MessageDigest messagedigest = MessageDigest.getInstance("SHA-1");
		byte abyte0[] = new byte[0];
		String s1 = "{SHA}";
		BASE64Encoder base64encoder = new BASE64Encoder();
		messagedigest.reset();
		messagedigest.update(s.getBytes());
		messagedigest.update(abyte0);
		byte abyte1[] = messagedigest.digest();
		String s2 = new String(s1 + base64encoder.encodeBuffer(concatenate(abyte1, abyte0)));
		return s2;
	}

	public String MD5(String s) throws IOException, NoSuchAlgorithmException {
		MessageDigest messagedigest = MessageDigest.getInstance("MD5");
		String s1 = "{MD5}";
		BASE64Encoder base64encoder = new BASE64Encoder();
		messagedigest.reset();
		messagedigest.update(s.getBytes());
		byte abyte0[] = messagedigest.digest();
		String s2 = new String(s1 + base64encoder.encodeBuffer(abyte0));
		return s2;
	}

	public String[] getUserInfoBySignOnKey(String s) {
		resultCode = -1;
		resultCodeString = new String("The Cookie is not found!");
		String as[] = null;
		Object obj = null;
		Object obj1 = null;
		String s1 = null;
		String s2 = null;
		if (ld.getAuthenticationDN() != null)
			s1 = new String(ld.getAuthenticationDN());
		if (ld.getAuthenticationPassword() != null)
			s2 = new String(ld.getAuthenticationPassword());
		try {
			ld.authenticate("uid=cookie,ou=Users,o=cht,c=tw", "#coo*kie");
		} catch (LDAPException ldapexception) {
			resultCodeString = new String(ldapexception.toString());
			resultCode = ldapexception.getLDAPResultCode();
			try {
				ld.authenticate(s1, s2);
			} catch (LDAPException ldapexception3) {
			}
			return null;
		}
		try {
			String s3 = new String("(initials=" + s + ")");
			String as1[] = { "cn", "uid" };
			LDAPSearchResults ldapsearchresults = ld.search(base, LDAPv2.SCOPE_SUB, s3, as1, false);
			if (ldapsearchresults == null) {
				try {
					ld.authenticate(s1, s2);
				} catch (LDAPException ldapexception4) {
				}
				return null;
			}
			while (ldapsearchresults.hasMoreElements()) {
				LDAPEntry ldapentry;
				try {
					ldapentry = ldapsearchresults.next();
				} catch (LDAPReferralException ldapreferralexception) {
					System.out.println("Search references: ");
					LDAPUrl aldapurl[] = ldapreferralexception.getURLs();
					for (int j = 0; j < aldapurl.length; j++)
						System.out.println("\t" + aldapurl[j].getUrl());

					continue;
				} catch (LDAPException ldapexception5) {
					resultCodeString = new String(ldapexception5.toString());
					resultCode = ldapexception5.getLDAPResultCode();
					continue;
				}
				as = new String[3];
				LDAPAttribute ldapattribute = ldapentry.getAttribute("cn");
				int i = ldapattribute.size();
				byte abyte0[][];
				if (i != 0 && (abyte0 = ldapattribute.getByteValueArray()) != null)
					try {
						as[0] = new String(abyte0[0], "Big5");
					} catch (Exception exception) {
						try {
							ld.authenticate(s1, s2);
						} catch (LDAPException ldapexception6) {
						}
						return null;
					}
				else
					as[0] = null;
				ldapattribute = ldapentry.getAttribute("uid");
				i = ldapattribute.size();
				if (i != 0 && (abyte0 = ldapattribute.getByteValueArray()) != null)
					try {
						as[1] = new String(abyte0[0], "Big5");
					} catch (Exception exception1) {
						try {
							ld.authenticate(s1, s2);
						} catch (LDAPException ldapexception7) {
						}
						return null;
					}
				else
					as[1] = null;
				as[2] = new String(ldapentry.getDN());
				resultCode = 0;
				resultCodeString = new String("Search is successful!");
			}
		} catch (LDAPException ldapexception1) {
			resultCodeString = new String(ldapexception1.toString());
			resultCode = ldapexception1.getLDAPResultCode();
		}
		try {
			ld.authenticate(s1, s2);
		} catch (LDAPException ldapexception2) {
		}
		return as;
	}

	public String whoAmI() {
		return ld.getAuthenticationDN();
	}

	public String getSingleStringValueByKeyAndPwd(String s, String s1, String s2, String s3) {
		if (s == null || s.length() < 1) {
			resultCodeString = new String("The Key_Name is empty!");
			resultCode = -1;
			return null;
		}
		if (s1 == null || s1.length() < 1) {
			resultCodeString = new String("The Key_Value is empty!");
			resultCode = -1;
			return null;
		}
		if (s2 == null || s2.length() < 1) {
			resultCodeString = new String("The PASSOWRD is empty!");
			resultCode = -1;
			return null;
		}
		String as[] = getDNsByKey(s, s1);
		if (resultCode != 0) {
			resultCodeString = new String(getResultCodeString());
			return null;
		}
		String s4 = ld.getAuthenticationDN();
		String s5 = ld.getAuthenticationPassword();
		for (int i = 0; i < as.length; i++) {
			authenticate(as[i], s2);
			if (resultCode == 0) {
				String s6 = getSingleStringValueByDN(s3, as[i]);
				String s7 = new String(resultCodeString);
				int j = resultCode;
				authenticate(s4, s5);
				resultCode = j;
				if (s7 != null)
					resultCodeString = new String(s7);
				else
					resultCodeString = null;
				return s6;
			}
		}

		authenticate(s4, s5);
		resultCodeString = new String("The Authentication is failed!");
		resultCode = -1;
		return null;
	}

	public byte[] getSingleByteValueByKeyAndPwd(String s, String s1, String s2, String s3) {
		if (s == null || s.length() < 1) {
			resultCodeString = new String("The Key_Name is empty!");
			resultCode = -1;
			return null;
		}
		if (s1 == null || s1.length() < 1) {
			resultCodeString = new String("The Key_Value is empty!");
			resultCode = -1;
			return null;
		}
		if (s2 == null || s2.length() < 1) {
			resultCodeString = new String("The PASSOWRD is empty!");
			resultCode = -1;
			return null;
		}
		String as[] = getDNsByKey(s, s1);
		if (resultCode != 0) {
			resultCodeString = new String(getResultCodeString());
			return null;
		}
		String s4 = ld.getAuthenticationDN();
		String s5 = ld.getAuthenticationPassword();
		for (int i = 0; i < as.length; i++) {
			authenticate(as[i], s2);
			if (resultCode == 0) {
				byte abyte0[] = getSingleByteValueByDN(s3, as[i]);
				String s6 = new String(resultCodeString);
				int j = resultCode;
				authenticate(s4, s5);
				resultCode = j;
				if (s6 != null)
					resultCodeString = new String(s6);
				else
					resultCodeString = null;
				return abyte0;
			}
		}

		authenticate(s4, s5);
		resultCodeString = new String("The Authentication is failed!");
		resultCode = -1;
		return null;
	}

	public String[] getMultiStringValuesByKeyAndPwd(String s, String s1, String s2, String s3) {
		if (s == null || s.length() < 1) {
			resultCodeString = new String("The Key_Name is empty!");
			resultCode = -1;
			return null;
		}
		if (s1 == null || s1.length() < 1) {
			resultCodeString = new String("The Key_Value is empty!");
			resultCode = -1;
			return null;
		}
		if (s2 == null || s2.length() < 1) {
			resultCodeString = new String("The PASSOWRD is empty!");
			resultCode = -1;
			return null;
		}
		String as[] = getDNsByKey(s, s1);
		if (resultCode != 0) {
			resultCodeString = new String(getResultCodeString());
			return null;
		}
		String s4 = ld.getAuthenticationDN();
		String s5 = ld.getAuthenticationPassword();
		for (int i = 0; i < as.length; i++) {
			authenticate(as[i], s2);
			if (resultCode == 0) {
				String as1[] = getMultiStringValuesByDN(s3, as[i]);
				String s6 = new String(resultCodeString);
				int j = resultCode;
				authenticate(s4, s5);
				resultCode = j;
				if (s6 != null)
					resultCodeString = new String(s6);
				else
					resultCodeString = null;
				return as1;
			}
		}

		authenticate(s4, s5);
		resultCodeString = new String("The Authentication is failed!");
		resultCode = -1;
		return null;
	}

	public byte[][] getMultiByteValuesByKeyAndPwd(String s, String s1, String s2, String s3) {
		if (s == null || s.length() < 1) {
			resultCodeString = new String("The Key_Name is empty!");
			resultCode = -1;
			return null;
		}
		if (s1 == null || s1.length() < 1) {
			resultCodeString = new String("The Key_Value is empty!");
			resultCode = -1;
			return null;
		}
		if (s2 == null || s2.length() < 1) {
			resultCodeString = new String("The PASSOWRD is empty!");
			resultCode = -1;
			return null;
		}
		String as[] = getDNsByKey(s, s1);
		if (resultCode != 0) {
			resultCodeString = new String(getResultCodeString());
			return null;
		}
		String s4 = ld.getAuthenticationDN();
		String s5 = ld.getAuthenticationPassword();
		for (int i = 0; i < as.length; i++) {
			authenticate(as[i], s2);
			if (resultCode == 0) {
				byte abyte0[][] = getMultiByteValuesByDN(s3, as[i]);
				String s6 = new String(resultCodeString);
				int j = resultCode;
				authenticate(s4, s5);
				resultCode = j;
				if (s6 != null)
					resultCodeString = new String(s6);
				else
					resultCodeString = null;
				return abyte0;
			}
		}

		authenticate(s4, s5);
		resultCodeString = new String("The Authentication is failed!");
		resultCode = -1;
		return null;
	}

	public String[][] getByAttributes(String s, String s1, String as[]) {
		resultCode = -1;
		resultCodeString = new String("The attributes are not found!");
		if (s == null || s.length() < 1) {
			resultCodeString = new String("myBase can not be NULL!");
			return null;
		}
		if (s1 == null || s1.length() < 1) {
			resultCodeString = new String("You need assign BASE|ONE|SUB!");
			return null;
		}
		if (!s1.equalsIgnoreCase("BASE") && !s1.equalsIgnoreCase("ONE") && !s1.equalsIgnoreCase("SUB")) {
			resultCodeString = new String("Wrong myScope value!");
			return null;
		}
		if (as == null || as.length < 1) {
			resultCodeString = new String("myAttributes can not be empty!");
			return null;
		}
		String s2 = null;
		s2 = new String("(&(" + as[0] + "=*)");
		for (int i = 1; i < as.length; i++)
			s2 = new String(s2 + "(" + as[i] + "=*)");

		s2 = new String(s2 + ")");
		Object obj = null;
		Object obj1 = null;
		int j = 0;
		String as1[][] = null;
		try {
			LDAPSearchResults ldapsearchresults;
			if (s1.equalsIgnoreCase("ONE"))
				ldapsearchresults = ld.search(s, LDAPv2.SCOPE_ONE, s2, as, false);
			else if (s1.equalsIgnoreCase("SUB"))
				ldapsearchresults = ld.search(s, LDAPv2.SCOPE_SUB, s2, as, false);
			else
				ldapsearchresults = ld.search(s, LDAPv2.SCOPE_BASE, s2, as, false);
			while (ldapsearchresults.hasMoreElements())
				try {
					LDAPEntry ldapentry = ldapsearchresults.next();
					j++;
				} catch (LDAPReferralException ldapreferralexception) {
				} catch (LDAPException ldapexception1) {
					resultCodeString = new String(ldapexception1.toString());
					resultCode = ldapexception1.getLDAPResultCode();
					return null;
				}
			if (j == 0)
				return null;
			as1 = new String[j][as.length + 1];
			for (int k = 0; k < j; k++) {
				for (int l = 0; l < as.length + 1; l++)
					as1[k][l] = null;

			}

			j = 0;
			if (s1.equalsIgnoreCase("ONE"))
				ldapsearchresults = ld.search(s, LDAPv2.SCOPE_ONE, s2, as, false);
			else if (s1.equalsIgnoreCase("SUB"))
				ldapsearchresults = ld.search(s, LDAPv2.SCOPE_SUB, s2, as, false);
			else
				ldapsearchresults = ld.search(s, LDAPv2.SCOPE_BASE, s2, as, false);
			while (ldapsearchresults.hasMoreElements()) {
				try {
					LDAPEntry ldapentry1 = ldapsearchresults.next();
					as1[j][0] = ldapentry1.getDN();
					for (int i1 = 0; i1 < as.length; i1++) {
						LDAPAttribute ldapattribute = ldapentry1.getAttribute(as[i1]);
						if (ldapattribute != null) {
							String as2[] = ldapattribute.getStringValueArray();
							if (as2 != null && as2.length > 0)
								as1[j][i1 + 1] = new String(as2[0]);
						}
					}

				} catch (LDAPReferralException ldapreferralexception1) {
					continue;
				} catch (LDAPException ldapexception2) {
					resultCodeString = new String(ldapexception2.toString());
					resultCode = ldapexception2.getLDAPResultCode();
					return null;
				}
				j++;
			}
		} catch (LDAPException ldapexception) {
			resultCodeString = new String(ldapexception.toString());
			resultCode = ldapexception.getLDAPResultCode();
			return null;
		}
		resultCodeString = new String("successfully!");
		resultCode = 0;
		return as1;
	}

	public int getConnectTimeout() {
		return ld.getConnectTimeout();
	}

	public void setConnectTimeout(int timeout) {
		ld.setConnectTimeout(timeout);
	}

	public void setTimeOption(Integer integer) {
		resultCode = 0;
		resultCodeString = new String("setTimeOption is success!");
		try {
			ld.setOption(LDAPv2.TIMELIMIT, integer);
		} catch (LDAPException ldapexception) {
			resultCodeString = new String(ldapexception.toString());
			resultCode = ldapexception.getLDAPResultCode();
			return;
		}
	}

	public void authenticate(int version, String dn, String passwd) {
		resultCode = 0;
		resultCodeString = new String("The authenticate is success!");
		try {
			ld.authenticate(version, dn, passwd);
		} catch (LDAPException ldapexception) {
			resultCodeString = new String(ldapexception.toString());
			resultCode = ldapexception.getLDAPResultCode();
			return;
		}
	}

	private LDAPConnection ld;
	private int resultCode;
	private String resultCodeString;
	private String base;
	private LDAPSchema dirSchema;
	private static String hexits = "0123456789abcdef";
}
